/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package doda2;

import javax.jms.MessageListener;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.JMSException;
import javax.jms.MessageFormatException;
/**
 *
 * @author Shadownest
 */
public class Listener implements MessageListener
{
    private SmartToursClient STClient;
    
    public Listener(SmartToursClient smartToursClient)
    {
        STClient = smartToursClient;
    }
    
    public void onMessage(Message message)
    {
        try
        {
            if (message instanceof ObjectMessage)
            {
                Invoice invoice;
                ObjectMessage objectMessage = (ObjectMessage) message;
                invoice = (Invoice) objectMessage.getObject();
                System.out.println("Reading object message: " + invoice.getInvoiceInformation());
                STClient.sendServiceOperatorMessage("Package paid");
                STClient.sendServiceOperatorPaiementCallBack(invoice);
                STClient.stop();
            }
            else
            {
                System.err.println("Message is not a TextMessage/ObjectMessage");
            }
        }
        catch (MessageFormatException e)
        {
            System.err.println("Object deserialization failed: " + e.toString());
        }
        catch (JMSException e)
        {
            System.err.println("JMS exception in onMessage(): " + e.toString());
        }
        catch (Throwable t)
        {
            System.err.println("Exception in onMessage():" + t.getMessage());
        }
    }
}
